package cn.zjweu.service.impl;

import cn.zjweu.dao.CartDao;
import cn.zjweu.dao.OrderDao;
import cn.zjweu.dao.UserDao;
import cn.zjweu.dao.impl.CartDaoImpl;
import cn.zjweu.dao.impl.OrderDaoImpl;
import cn.zjweu.dao.impl.UserDaoImpl;
import cn.zjweu.domain.Order;
import cn.zjweu.domain.User;
import cn.zjweu.service.UserService;

import java.util.List;

public class UserServiceImpl implements UserService {

    private UserDao userDao = new UserDaoImpl();
    private CartDao cartDao = new CartDaoImpl();
    private OrderDao orderDao = new OrderDaoImpl();

    @Override
    public User findUserByNameAndPWD(String username, String password) {
        return userDao.findUserByNameAndPWD(username, password);
    }

    @Override
    public User findUsername(String username) {
        return userDao.findUsername(username);
    }

    @Override
    public boolean saveUser(String username, String password, String trueName, String telephone, String city, String address) {
        return userDao.saveUser(username, password, trueName, telephone, city, address);
    }

    @Override
    public boolean editUser(User user) {
        return userDao.editUser(user);
    }

    @Override
    public User findUserById(int userId) {
        return userDao.findUserById(userId);
    }

    @Override
    public List<User> findAllUser() {
        return userDao.findAllUser();
    }

    @Override
    public void resetPWD(int userId) {
        userDao.resetPWD(userId);
    }

    @Override
    public void delUserById(int userId) {
        User user = userDao.findUserById(userId);
        orderDao.delOrderDetailByUsername(user.getUsername());
        orderDao.delOrderByUsername(user.getUsername());
        cartDao.clearCartByUserId(userId);
        userDao.delUserById(userId);
    }

}
